<template lang="pug">
  div
    CommonDialog(:width="800", :height="400", title="查看子菜单", @close="close")
      template(slot="content")
        .global-container-content
          .content-header
            div 菜单名称
            div 菜单路径
            div 操作人
            div 操作时间
            div 操作
          .content-body.view-menu-body
            .content-item(v-for="item in menuList")
              div {{item.menuName}}
              div {{item.path}}
              div {{item.updateUserName}}
              div {{item.updateTime}}
              .operate-group
                .text-delete(v-if="menuList.length > 1", @click="deleteMenu(item.menuId)") 删除
      template(slot="footer")
        .btn-no-margin.btn-cancel(@click="close") 关闭
</template>

<script>
import qs from 'qs'
export default {
  props: {
    menuGroupId: String
  },
  data () {
    return {
      menuList: []
    }
  },
  methods: {
    deleteMenu (menuId) {
      this.$store.set('dialog/operateConfirmInfo', {
        show: true,
        text: '是否确认删除当前菜单?',
        confirmCallback: async () => {
          const {code, msg} = (await this.$http.post('/manage/menu/delete-menu', qs.stringify({
            menuGroupId: this.menuGroupId,
            menuId
          }))).data
          if (code === 0) {
            this.$store.set('dialog/blackInfo', {
              show: true,
              text: '删除成功'
            })
          } else {
            this.$store.set('dialog/operateTipInfo', {
              show: true,
              text: msg
            })
          }
          this.init()
          this.menuFlush()
        }
      })
    },
    menuFlush () {
      this.$store.set('base/menuFlush', true)
    },
    close () {
      this.$emit('close')
    },
    async init () {
      const {data} = (await this.$http.post(`/manage/menu/init-menu-list/${this.menuGroupId}`)).data
      this.menuList = data
    }
  },
  mounted () {
    this.init()
  }
}
</script>

<style scoped lang="stylus">
  .view-menu-body
    height calc(100% - 44px) !important
</style>
